package com.asia5b.a5mall.middleware.bind

import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.asia5b.a5mall.middleware.utils.WImageLoader

/**
 * Created by zhangyuncai on 2019/12/21.
 * @Note   todo databinding辅助类 绑定所有图片
 */
object ImageBindingHelper {

    /**
     * @Note   加载图片
     * @param  imageView 需要加载图片的ImageView
     * @param  url       图片Url
     */
    @BindingAdapter(value = arrayOf("bind:url"), requireAll = false)
    @JvmStatic
    fun loadImage(imageView: ImageView?, url: String?) {
        if (imageView == null || url == null || url == "") {
            return
        }
        WImageLoader.displayImage(url, imageView)
    }

    /**
     * @Note   加载图片 倒角5dp
     * @param  imageView 需要加载图片的ImageView
     * @param  url       图片Url
     */
    @BindingAdapter(value = arrayOf("bind:url_round5"), requireAll = false)
    @JvmStatic
    fun loadRound5Image(imageView: ImageView?, url: String?) {
        if (imageView == null || url == null || url == "") {
            return
        }
        WImageLoader.displayRoundImage(url, imageView, 5)
    }

    /**
     * @Note   加载图片 倒角10dp
     * @param  imageView 需要加载图片的ImageView
     * @param  url       图片Url
     */
    @BindingAdapter(value = arrayOf("bind:url_round10"), requireAll = false)
    @JvmStatic
    fun loadRound10Image(imageView: ImageView?, url: String?) {
        if (imageView == null || url == null || url == "") {
            return
        }
        WImageLoader.displayRoundImage(url, imageView, 10)
    }



}